<template>
  <div>
    <div class="search">
      <div class="positon">
        <h3>Search Github Users</h3>
        <div>
          <input type="text" placeholder="enter the name you search" v-model="keyword">
          <button @click="search">Search</button>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import axios from 'axios'
export default {
  name: 'search',
  data () {
    return {
      keyword: ''
    }
  },
  methods: {
    search () {
      this.$bus.$emit('getInfoData', { users: [], isFirst: false, isLoading: true, errorMsg: '' })
      this.$http.get(`https://api.github.com/search/users?q=${this.keyword}`).then(
        response => {
          console.log('我收到数据了',);
          this.$bus.$emit('getInfoData', { users: response.data.items, isFirst: false, isLoading: false, errorMsg: '' })
        },
        error => {
          console.log('出错了！', error.message);
          this.$bus.$emit('getInfoData', { users: [], isFirst: false, isLoading: false, errorMsg: error.message })
        }
      )
    }
  }
}
</script>

<style scoped>
.search {
  position: relative;
  width: 600px;
  height: 200px;
  background-color: #ededed;
}
.positon {
  position: absolute;
  left: 50px;
  top: 60px;
}
</style>